package com.aidex.system.controller;

import java.util.List;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.system.domain.ApiLog;
import com.aidex.system.service.ApiLogService;

/**
 * 接口日志Controller
 * @author jmy
 * @email jmyinjg@163.com
 * @date 2021-11-14
 */
@RestController
@RequestMapping("/system/apiLog")
public class ApiLogController extends BaseController
{
    @Autowired
    private ApiLogService apiLogService;

    /**
     * 查询接口日志列表
     */
//    @PreAuthorize("@ss.hasPermi('system:apiLog:list')")
    @GetMapping("/list")
    public R<PageInfo> list(ApiLog apiLog, HttpServletRequest request, HttpServletResponse response)
    {
        apiLog.setPage(new PageDomain(request, response));
        return R.data(apiLogService.findPage(apiLog));
    }

    /**
     * 获取接口日志详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:apiLog:query')")
    @GetMapping(value = "/{id}")
    public R<ApiLog> detail(@PathVariable("id") String id)
    {
        return R.data(apiLogService.get(id));
    }

    /**
     * 新增接口日志
     */
//    @PreAuthorize("@ss.hasPermi('system:apiLog:add')")
    @Log(title = "接口日志", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  ApiLog apiLog)
    {
        return R.status(apiLogService.save(apiLog));
    }

    /**
     * 修改接口日志
     */
//    @PreAuthorize("@ss.hasPermi('system:apiLog:edit')")
    @Log(title = "接口日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated ApiLog apiLog)
    {
        return R.status(apiLogService.save(apiLog));
    }


    /**
     * 删除接口日志
     */
//    @PreAuthorize("@ss.hasPermi('system:apiLog:remove')")
    @Log(title = "接口日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(apiLogService.deleteApiLogByIds(ids));
    }


    /**
     * 导出接口日志列表
     */
//    @PreAuthorize("@ss.hasPermi('system:apiLog:export')")
    @Log(title = "接口日志", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(ApiLog apiLog)
    {
        List<ApiLog> list = apiLogService.findList(apiLog);
        ExcelUtil<ApiLog> util = new ExcelUtil<ApiLog>(ApiLog.class);
        return util.exportExcel(list, "apiLog");
    }

}
